using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace WoWAddonRefresh.Entities {
    public class Version {
        private string name;
        public string Name {
            get { return name; }
            set { name = value; }
        }

        private string downloadURL;
        public string DownloadURL {
            get { return downloadURL; }
            set { downloadURL = value; }
        }

        private DateTime uploadDate;
        public DateTime UploadDate {
            get { return uploadDate; }
            set { uploadDate = value; }
        }

        #region UploadDateComparer

        private class UploadDateComparer : IComparer {
            private bool ascending = true;

            public UploadDateComparer(bool ascending) {
                this.ascending = ascending;
            }

            int IComparer.Compare(object entity1, object entity2) {
                Version item1 = entity1 as Version;
                Version item2 = entity2 as Version;
                if (item1 == null) {
                    throw new ArgumentException(
                        string.Format("Invalid type of object to compare : {0}", item1.GetType().FullName), "entity1");
                }

                if (item2 == null) {
                    throw new ArgumentException(
                        string.Format("Invalid type of object to compare : {0}", item2.GetType().FullName), "entity2");
                }


                return ascending ? item1.UploadDate.CompareTo(item2.UploadDate) : item2.UploadDate.CompareTo(item1.UploadDate);


            }
        }

        [NonSerialized()]
        public static IComparer UploadDateComparerAscending = new UploadDateComparer(true);

        [NonSerialized()]
        public static IComparer UploadDateComparerDescending = new UploadDateComparer(false);

        #endregion UploadDateComparer
    }

    public class VersionCollection : List<Version> {
    }
}
